import json

from django.http import JsonResponse
from django.views.generic.base import View
from goods.models import Goods
from django.core.serializers import serialize


class GoodsList(View):
    def get(self, request):
        good_list = []
        goods = Goods.objects.all()[:10]
        # for good in goods:
        #     good_info = {}
        #     good_info['goodname'] = good.name
        #     good_info['shop_price'] = good.shop_price
        #     good_list.append(good_info)

        good_list = serialize('json', goods)
        good_list = json.loads(good_list)
        return JsonResponse(good_list, safe=False)
